Release 10.1A: OpenEdge Data Management:
SQL Development
Connecting from a Java application using a URL
A Java application must perform two steps to connect to an OpenEdge database through a JDBC driver:
To load the JDBC driver, call the
Class.forNamemethod in the JDBC application. TheClass.forNamemethod takes the fully qualified class name of the JDBC driver as its argument. The fully qualified class name for the JDBC driver iscom.ddtek.jdbc.openedge.OpenEdgeDriver.This class name is case-sensitive and must be typed exactly as shown. The
Class.forNamemethod also registers the specified JDBC driver with the Driver Manager class so that the driver is available for connections.Here is an example of the call needed to load and register the driver:
Now that the JDBC driver has been loaded and registered, the
DriverManager.getConnectionmethod must be called to establish a connection to the database. ThegetConnectionmethod takes three arguments:
- A string containing a URL. The Driver Manager uses this URL to find a driver that can connect to the database represented by the given URL. Once the driver is found, the URL is used by the Driver class to establish the connection to the database.
OpenEdge syntax for the URL string is:
See the "JDBC URL connection string" section for an explanation of each component.
- The ID of the user trying to connect to the database.
- The user’s password.
Database connection examples
Several variations of the call needed to connect to the database follow:
- Variation 1
This is an example of how to connect to the OpenEdge database using Variation 1:
- Variation 2
In this variation
infois a Properties object that contains a string of tag/value pairs used for connecting to the database. Normally theinfoobject would include at least the user ID and password. The password is optional and defaults toNULL. However, once theCREATE USERstatement has been executed and a user is created in the database, a password is required.The JDBC driver expects the user ID tag to be named
userand the password tag to be namedpassword. The user and password tags are case-sensitive and must be in all lowercase letters.This is an example of how to connect to the database using Variation 2 (tag/value pairs):
- Variation 3
This variation takes only the URL as an argument. The URL in this case contains the
userandpasswordtags shown in Variation 2. Thepasswordis optional and defaults toNULL. However, once theCREATE USERstatement has been executed and a user is created in the OpenEdge database, a password is required.The JDBC driver expects the user ID tag to be named user and the password tag to be named password. The
userandpasswordtags are case sensitive and must be in all lowercase letters.This is an example of how to connect to the OpenEdge database using Variation 3:
- JDBC URL connection string
The OpenEdge JDBC URL string has the following syntax:
This is an example of a connection string:
This is an example of a connection string, using the optional
service_nameparameter:
The components of the URL string are:
jdbc:datadirect:openedge://
jdbcis the protocol to be used. The protocol in a JDBC URL is alwaysjdbc.
datadirectis the subprotocol and it designates the name of the JDBC driver.
openedgeindicates that the driver is for OpenEdge.hostThe name of the host on which the OpenEdge database resides. If this is not specified it defaults to
localhost(localhostis valid only if the database is not remote). Thehostismyhostin the example.portPort number or service name to be used for the connection. The
Note: If you specify theportis6718in the first example.service_name, the port must be-1,as shown in the second example.db_nameThe name of the database. The
db_nameissports2000in the example.service_nameAn optional parameter, indicating the name of the service. The
service_nameismyservicein the example. If you specifyservice_name, theportmust be-1.schema_nameIndicates the schema to be used during statement processing. For more information about the
defaultSchemaconnection parameter, see the "JDBC connection parameters" section.CacheSizeIndicates how many entries will be in the statement cache. For more information about the
statementCacheSizeconnection parameter, see the "JDBC connection parameters" section.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |